// : v.book.read.tip.state.demo1.KissingPrincess2.java
package v.book.read.tip.state.demo1;

import junit.framework.TestCase;

/**
 * 状态模式
 * @author 小败
 */
class Creature2 {
    
    private interface State {
        String response();
    }
    
    // 青蛙
    private class Frog implements State {
        public String response() {
            return "Ribbet!";
        }
    }
    
    // 王子
    private class Prince implements State {
        public String response() {
            return "Darling!";
        }
    }

    private State state = new Frog();

    public void greet() {
        System.out.println(state.response());
    }

    public void kiss() {
        state = new Prince();
    }
}


public class KissingPrincess2 extends TestCase {
    Creature2 creature = new Creature2();

    public void test() {
        creature.greet();
        creature.kiss();
        creature.greet();
    }

    public static void main(String args[]) {
        junit.textui.TestRunner.run(KissingPrincess2.class);
    }
} // /:~
